<template>
  <div class="container">
    <headerBar
      :title="stockInfo.status=='3'?local.splitDetail:local.continueSplitting"
      @changeLan="changeLan"
      @pageReturn="pageReturn"
    ></headerBar>
    <div class="all" :style="{paddingTop: pdt+'px'}">
      <!-- 拆分信息(原商品) -->
      <div class="split-title">{{local.splitMessage}}</div>
      <div class="top">
        <div class="select-panel">
          <div class="panel-goods">
            <div class="name">{{local.supplier}}：</div>
            <div class="names-goods">{{stockInfo.supplierName}}</div>
          </div>
          <div class="panel-goods">
            <div class="name">{{local.buyArea}}：</div>
            <div class="names-goods">{{stockInfo.buyAreaName || ''}}</div>
          </div>
          <div class="panel-goods">
            <div class="name">{{local.goodsName}}：</div>
            <div class="names-goods">{{stockInfo.goodsName}}</div>
          </div>
          <div class="panel-goods">
            <div class="name">{{local.warehouseIn}}：</div>
            <div class="names-goods">{{stockInfo.warehouseName}}</div>
          </div>
        </div>
      </div>
      <div class="select-photo">
        <div class="a">{{local.photosBeforeAcceptance}}</div>
        <div class="b">
          <div class="page">
            <div class="weui-uploader__bd">
              <div class="weui-uploader__files" id="uploaderFiles">
                <block v-for="(ite, index) in stockInfo.beginPicUrlList" :key="index">
                  <div
                    class="weui-uploader__file"
                    @click="predivImageStart"
                    :id="item"
                    :data-urls="stockInfo.beginPicUrlList"
                  >
                    <!-- <div>{{ite}}</div> -->
                    <img class="weui-uploader__img" :src="url + ite" mode="aspectFill" />
                  </div>
                </block>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="stock-detail-panel">
        <div class="stock-detail-belt">
          <span class="name">{{local.beltType}}：</span>
          <div class style="border-bottom: 2rpx solid;">
            <picker class="weui-btn" disabled :value="indexPicker" :range="array">
              <input type="default" v-model=" beltName" disabled :placeholder="local.option" />
              <span class="unit">▼</span>
            </picker>
          </div>
        </div>
        <div class="msg-detail-grade">
          <span class="name">{{local.grade}}：</span>
          <div class style="border-bottom: 2rpx solid;">
            <picker class="weui-btn" disabled :value="indexPicker" :range="array">
              <input type="default" v-model="levelName" disabled :placeholder="local.option" />
              <span class="unit">▼</span>
            </picker>
          </div>
        </div>
        <div class="msg-detail-thickness">
          <span class="name">{{local.thickness}}：</span>
          <div class style="border-bottom: 2rpx solid;">
            <input v-model="stockInfo.sizeHeight" disabled :placeholder="local.peleaseEnter" />
            <span class="unit">MM</span>
          </div>
        </div>
        <div class="msg-detail-width">
          <span class="name">{{local.width}}：</span>
          <div class style="border-bottom: 2rpx solid;">
            <input v-model="stockInfo.sizeWidth" disabled :placeholder="local.peleaseEnter" />
            <span class="unit">MM</span>
          </div>
        </div>
        <div class="msg-detail-long">
          <span class="name">{{local.length}}：</span>
          <div class style="border-bottom: 2rpx solid;">
            <input v-model="stockInfo.sizeLong" disabled :placeholder="local.peleaseEnter" />
            <span class="unit">M</span>
          </div>
        </div>
        <div class="msg-detail-long">
          <span class="name">{{local.weight}}：</span>
          <div class style="border-bottom: 2rpx solid;">
            <input v-model="stockInfo.weight" disabled :placeholder="local.peleaseEnter" />
            <span class="unit">T</span>
          </div>
        </div>
      </div>
      <div class="select-photo">
        <div class="a">{{local.photosAfterAcceptance}}</div>
        <div class="b">
          <div class="page">
            <div class="weui-uploader__bd">
              <div class="weui-uploader__files" id="uploaderFiles">
                <block v-for="(ite, index) in stockInfo.endPicUrlList" :key="index">
                  <div
                    class="weui-uploader__file"
                    @click="predivImageEnd"
                    :id="ite"
                    :data-urls="stockInfo.endPicUrlList"
                  >
                    <img class="weui-uploader__img" :src="url + ite" mode="aspectFill" />
                  </div>
                </block>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="remark">
        <div>{{local.remark1}}:</div>
        <textarea
          style="height: 100rpx;max-width: 879rpx;resize: none;"
          disabled
          v-model="stockInfo.remark"
        ></textarea>
      </div>

      <!-- 拆分明细 -->
      <div class="split-title">{{local.splittingDetail}}</div>
      <div class v-for="(item, i) in addList" :key="i">
        <block v-if="item">
          <div class="top">
            <div class="select-panel" style="margin-bottom: 20rpx;">
              <div class="opreate jt_flex jt_flex_row_right">
              <div
                class="open"
                @click="openOrClose(addList,i)"
              >{{item.open ? local.fold : local.unfold}}</div>
              <div class="detele-text" @click="deleteRow(addList,i)">{{local.deletesingle}}</div>
            </div>
              <div class="panel-goods">
                <div class="name">{{local.goodsName}}：</div>
                <div class="names-goods">{{item.goodsName}}</div>
              </div>
            </div>
          </div>
          <block v-if="item.open">
            <div class="stock-detail-panel">
              <div class="panel-ware">
                <div class="name">
                  <span style="color: red;">*</span>
                  {{local.warehouseIn}}：
                </div>
                <div class="page" style="border-bottom: 2rpx solid;">
                  <picker
                    class="weui-btn"
                    @change="PickerWarehouseChange"
                    :value="indexWarePicker"
                    :data-i="i"
                    :range="arrayWarehouse"
                    :range-key="'warehouseName'"
                  >
                    <input
                      type="default"
                      v-model="item.warehouseName"
                      :placeholder="local.option"
                      disabled
                    />
                    <span class="unit">▼</span>
                  </picker>
                </div>
              </div>
            </div>
            <div class="stock-detail-panel">
              <div class="stock-detail-belt">
                <span class="name">
                  <span style="color: red;width: 2rpx;">*</span>
                  {{local.beltType}}：
                </span>
                <div class style="border-bottom: 2rpx solid;">
                  <picker
                    class="weui-btn"
                    @change="PickerBeltChange"
                    :value="indexBeltPicker"
                    :data-i="i"
                    :data-m="arrayBelt[indexBeltPicker].dictLabel"
                    :range="arrayBelt"
                    :range-key="'dictLabel'"
                  >
                    <input
                      type="default"
                      v-model="item.beltTypeNameInput"
                      :placeholder="local.option"
                      disabled
                    />
                    <span class="unit">▼</span>
                  </picker>
                </div>
              </div>
              <div
                class="msg-detail-thickness"
                v-if="item.beltTypeNameInputFlag||item.beltType=='4'"
              >
                <span class="name">
                  <span style="color: red;width: 2rpx;">*</span>
                  {{local.beltTypeName}}：
                </span>
                <div class style="border-bottom: 2rpx solid;">
                  <input
                    v-model="item.beltTypeName"
                    @input="changeBeltTypeNameInput"
                    :data-i="i"
                    :placeholder="local.peleaseEnter"
                  />
                </div>
              </div>
              <div class="msg-detail-grade">
                <span class="name">
                  <span style="color: red;width: 2rpx;">*</span>
                  {{local.grade}}：
                </span>
                <div class style="border-bottom: 2rpx solid;">
                  <picker
                    class="weui-btn"
                    @change="PickerLevelChange"
                    :value="indexLevelPicker"
                    :data-i="i"
                    :data-m="arrayLevel[indexLevelPicker].dictLabel"
                    :range="arrayLevel"
                    :range-key="'dictLabel'"
                  >
                    <input
                      type="default"
                      v-model="item.goodsLevelName"
                      :placeholder="local.option"
                      disabled
                    />
                    <span class="unit">▼</span>
                  </picker>
                </div>
              </div>
            </div>
            <div class="select-photo">
              <div class="a name">
                <span style="color: red;width: 2rpx;">*</span>
                {{local.photosBeforeAcceptance}}
              </div>
              <div class="b">
                <div class="page">
                  <div class="weui-uploader__bd">
                    <div class="weui-uploader__files" id="uploaderFiles">
                      <block v-for="(ite, ih) in item.beginPicUrlList" :key="ih">
                        <div
                          class="weui-uploader__file"
                          @click="predivImage1"
                          :id="ite"
                          :data-urls="item.beginPicUrlList"
                        >
                          <img class="weui-uploader__img" :src="url + ite" mode="aspectFill" />
                          <div
                            v-if="stockInfo.status!=='3'"
                            style="color: #DE6E7C;display: flex;justify-content: center;font-size: 26rpx;"
                            @click="deleteImgBefore(ite, i)"
                          >{{local.deletesingle}}</div>
                        </div>
                      </block>
                    </div>
                    <div class="weui-uploader__input-box" v-if="stockInfo.status!=='3'">
                      <div class="weui-uploader__input" @click="chooseImage(e, i)"></div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="stock-detail-panel">
              <div class="msg-detail-thickness">
                <span class="name">
                  <span style="color: red;width: 2rpx;">*</span>
                  {{local.thickness}}：
                </span>
                <div class style="border-bottom: 2rpx solid;">
                  <input type="digit" v-model="item.sizeHeight" :placeholder="local.peleaseEnter" />
                  <span class="unit">MM</span>
                </div>
              </div>
              <div class="msg-detail-width">
                <span class="name">
                  <span style="color: red;width: 2rpx;">*</span>
                  {{local.width}}：
                </span>
                <div class style="border-bottom: 2rpx solid;">
                  <input type="digit" v-model="item.sizeWidth" :placeholder="local.peleaseEnter" />
                  <span class="unit">MM</span>
                </div>
              </div>
              <div class="msg-detail-long">
                <span class="name">
                  <span style="color: red;width: 2rpx;">*</span>
                  {{local.length}}：
                </span>
                <div class style="border-bottom: 2rpx solid;">
                  <input type="digit" v-model="item.sizeLong" :placeholder="local.peleaseEnter" />
                  <span class="unit">M</span>
                </div>
              </div>
              <div class="msg-detail-long">
                <span class="name">
                  <span style="color: red;width: 2rpx;">*</span>
                  {{local.weight}}：
                </span>
                <div class style="border-bottom: 2rpx solid;">
                  <input type="digit" v-model="item.weight" :placeholder="local.peleaseEnter" />
                  <span class="unit">T</span>
                </div>
              </div>
            </div>
            <div class="remark">
              <div>{{local.remark1}}:</div>
              <textarea
                style="height: 100rpx;max-width: 879rpx;resize: none;"
                v-model="item.remark"
              ></textarea>
            </div>
            <div class="select-photo">
              <div class="a name">
                <span style="color: red;width: 2rpx;">*</span>
                {{local.photosAfterAcceptance}}
              </div>
              <div class="b">
                <div class="page">
                  <div class="weui-uploader__bd">
                    <div class="weui-uploader__files" id="uploaderFiles">
                      <block v-for="(ite, im) in item.endPicUrlList" :key="im">
                        <div
                          class="weui-uploader__file"
                          @click="predivImageEnd1"
                          :id="ite"
                          :data-urls="item.endPicUrlList"
                        >
                          <img class="weui-uploader__img" :src="url + ite" mode="aspectFill" />
                          <div
                            v-if="stockInfo.status!=='3'"
                            style="color: #DE6E7C;display: flex;justify-content: center;font-size: 26rpx;"
                            @click="deleteImgEnd(ite, i)"
                          >{{local.deletesingle}}</div>
                        </div>
                      </block>
                    </div>
                    <div class="weui-uploader__input-box" v-if="stockInfo.status!=='3'">
                      <div class="weui-uploader__input" @click="chooseImageEnd(e, i)"></div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </block>
        </block>
      </div>

      <!-- 底部按钮-->
      <div
        class="add-btn"
        @click="add()"
        v-if="stockInfo.status!=='3'"
      >+ {{addList.length == 0 ? local.adding : local.continueAdding}}</div>
      <div class="bottom-bar" v-if="pages == 2">
        <!-- 未拆分详情 -->
        <div class="sum" @click="deleteAndReturn">{{local.deleteAndReturn}}</div>
        <div class="btngroup">
          <div class="save-draft jt_flex_der jt_flex_row_right" @click="confirmSplit('save')">{{local.saveSplitOrder}}</div>
          <div class="confirm jt_flex_row_right" @click="confirmSplit('submit')">{{local.confirmSplit}}</div>
        </div>
      </div>
      <div class="bottom-bar" v-else-if="pages == 1&&stockInfo.status==2">
        <!-- 拆分中详情-->
        <div class="sum" @click="deleteAndReturn">{{local.deleteAndReturn}}</div>
        <div class="btngroup">
          <div class="save-draft jt_flex_der jt_flex_row_right" @click="confirmSplit('saveSplit')">{{local.saveSplitOrder}}</div>
          <div class="confirm jt_flex_row_right" @click="confirmSplit('confirmSplit')">{{local.confirmSplit}}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<!--<link rel="stylesheet" href="index.scss">-->
<script>
import home from "@/api/home"
import card from "@/components/card"
import headerBar from "@/components/headerBar"
import Shop from "../../../../config/shop"
import { throttle } from "@/utils/throttle"
import { dictMatching, previewImage } from "@/utils/index"
import { formatDate } from '@/utils/index'
export default {
  components: {
    card,
    headerBar,
  },
  onLoad(options) {
    this.initLang()
    this.pages = options.pages // 表示splitrecord 进入
    this.id = options.id
    if (this.pages == 2) {
      // 未拆封列表进来
      this.getProductListIdNotSplit()
    } else if (this.pages == 1) {
      // 拆分列表进来
      this.getProductListId()
    }
    this.getWarehouseList()
    this.getBelt()
    this.getLevel()
    this.pdt = this.globalData.CustomBar
  },
  computed: {
    beltName() {
      let a = this.arrayBelt.find(
        item => item.dictValue == this.stockInfo.beltType
      )
      return a ? a.dictLabel : this.stockInfo.beltType
    },
    levelName() {
      let a = this.arrayLevel.find(
        item => item.dictValue == this.stockInfo.goodsLevel
      )
      return a ? a.dictLabel : this.stockInfo.goodsLevel
    },
  },
  methods: {
    initLang(){
      this.local = wx.getStorageSync('local')
    },
    deleteRow(list, index){
      
      if(list[index].isNew == 0){
        //如果当前删除的是 详情
        // this.addList.splice(index,1)
        this.addList[index]=false
      }else {
        this.addList.splice(index,1)
        this.l = this.lockL
        this.addList.forEach((item)=>{
          if(item.isNew){
            item.goodsName = `${this.stockInfo.goodsName}-${this.l++}`
          }
        })
      }
      this.addList.push()
    },
    openOrClose(list, index) {
      list[index].open = !list[index].open
      list.push()
    },
    deleteImgBefore(ite, i) {
      this.addList[i].beginPicUrlList = this.addList[i].beginPicUrlList.filter(
        item => item !== ite
      )
    },
    deleteImgEnd(ite, i) {
      this.addList[i].endPicUrlList = this.addList[i].endPicUrlList.filter(
        item => item !== ite
      )
    },
    resetData(){
      this.addList = []
      this.stockInfo = {}
    },
    pageReturn() {
      this.resetData()
    },
    deleteAndReturn() {
      this.resetData()
      wx.redirectTo({
        url: '/packageA/pages/splitRecords/index?activeIndex=""',
      })
    },
    onShow() {
      this.initLang()
    },
    async getBelt() {
      const { rows } = await home.getBeltLevel({ dictType: "beltType" })
      this.arrayBelt = rows
    },
    async getLevel() {
      const { rows } = await home.getBeltLevel({ dictType: "goodsLevel" })
      this.arrayLevel = rows
    },
    changeLan(val) {
      this.local = val
    },
    PickerBeltChange(e) {
      this.indexBeltPicker = e.mp.detail.value
      this.addList[e.mp.currentTarget.dataset.i].beltType = this.arrayBelt[
        e.mp.detail.value
      ].dictValue
      this.addList[e.mp.currentTarget.dataset.i].beltTypeNameInput = this.arrayBelt[
        e.mp.detail.value
      ].dictLabel
      if (this.addList[e.mp.currentTarget.dataset.i].beltTypeNameInput == '其它'||this.addList[e.mp.currentTarget.dataset.i].beltTypeNameInput == '其他') {
        this.addList[e.mp.currentTarget.dataset.i].beltTypeNameInputFlag = true
      } else {
        this.addList[e.mp.currentTarget.dataset.i].beltTypeNameInputFlag = false
      }
    },
    PickerLevelChange(e) {
      this.indexLevelPicker = e.mp.detail.value
      this.addList[e.mp.currentTarget.dataset.i].goodsLevel = this.arrayLevel[
        e.mp.detail.value
      ].dictValue
      this.addList[
        e.mp.currentTarget.dataset.i
      ].goodsLevelName = this.arrayLevel[e.mp.detail.value].dictLabel
    },
    PickerWarehouseChange(e) {
      this.indexWarePicker = e.mp.detail.value
      this.addList[
        e.mp.currentTarget.dataset.i
      ].warehouseName = this.arrayWarehouse[e.mp.detail.value].warehouseName
      this.addList[
        e.mp.currentTarget.dataset.i
      ].warehouseId = this.arrayWarehouse[e.mp.detail.value].warehouseId
    },
    async getWarehouseList() {
      const { rows } = await home.getWarehouseList()
      this.arrayWarehouse = rows
    },
    dataVerification(data,type) {
      console.log(type);
      // 这里进行数据的校验，所有字段必须完整才可提交
      let flagStatus = false // 校验状态默认不通过
      if('save,saveSplit'.includes(type)){
        let  map = ['sizeHeight','sizeWidth','sizeLong','weight']
        // 如果是空值后端接受会报错 默认设置为0
        data.forEach(item =>{
          map.forEach(name=>{
            item[name] = item[name] || 0
          })
        })
        return flagStatus //保存接口不校验
      }
      const flag = { // 国际化文本映射
        goodsName: this.local.goodsName,
        warehouseName: this.local.warehouseIn,
        warehouseId: this.local.warehouseIn,
        remark: this.local.remark,
        beltType: this.local.beltType,
        goodsLevel: this.local.grade,
        beginPicUrl: this.local.photosBeforeAcceptance,
        sizeHeight: this.local.thickness,
        sizeWidth: this.local.width,
        sizeLong: this.local.length,
        weight: this.local.weight,
        beginPicUrlList: this.local.photosBeforeAcceptance,
      }
      const endPicFlag = {
        endPicUrl: this.local.photosAfterAcceptance,
        endPicUrlList: this.local.photosBeforeAcceptance,
      }
      //保存时，不用校验验收后的照片，提交时，需要校验
      const lastData = data
      const lastFlag = {...flag, ...endPicFlag}
      const verifiyList = [
            'warehouseId',
            'warehouseName',
            'beltType',
            'goodsLevel',
            'beginPicUrl',
            'beginPicUrlList',
            'sizeHeight',
            'sizeWidth',
            'sizeLong',
            'weight',
            'endPicUrl',
            'endPicUrlList'
      ]
      lastData.some(ite => {
        let resList = verifiyList.find(ver => ite[ver] == null || ite[ver] == '')
        if(resList) {
          wx.showToast({
              title: `【${ite.goodsName}】${lastFlag[resList]}${this.local.required}`,
              icon: "none",
              duration: 2000,
          })
          flagStatus = true
          return true
        }
      })
      return flagStatus
    },
    dataAggregate(data) {
      // 修改传入的数组，并返回计算结果
      data.forEach(item => {
        if(item){
        item.beginPicUrl = item.beginPicUrlList.join()
        item.endPicUrl = item.endPicUrlList.join()
        this.sumWeight += Number(item.weight)
        }
      })
      return data
    },
    getUrl(type) {
      let url = ""
      let activeIndex = 1
      switch (type) {
        case "submit":
          url = "/splitSave"
          activeIndex = 3
          break
        case "save":
          url = "/add"
          activeIndex = 2
          break
        case "saveSplit":
          url = "/editSave"
          activeIndex = 2
          break
        default:
          url = "/productSplitSave"
          activeIndex = 3
          break
      }
      return { url, activeIndex }
    },
    async submitData(goodsList, type) {
      wx.showLoading({
        title: `${this.local.jumping}`,
      })
      this.gotoPage(
        `/packageA/pages/splitRecords/index?activeIndex=${
          this.getUrl(type).activeIndex
        }`,
        type
      )
    },
    // 确认
    async confirmSplit(type) {
      const that = this
      this.sumWeight = 0 //合计重量
      if (this.addList.length == 0) {
        // 如果没有拆分明细那么提示添加拆分明细
        wx.showToast({
          title: this.local.splittingTip,
          duration: 2000,
          icon: "none",
        })
        return
      }
      this.addList = this.dataAggregate(this.addList).filter(item => item) //处理图片 重量
      const goodsList = this.addList

      if (!this.dataVerification(goodsList,type)) {
        const diff = this.sumWeight - this.stockInfo.weight
        if (Math.abs(diff) / this.stockInfo.weight > 0.2) {
          wx.showModal({
            title: `${this.local.tips}`,
            content: `${this.local.splitTip1}${diff > 0 ? ">" : "<"}${
              this.local.splitTip2
            }`,
            showCancel: true,
            success(res) {
              if (res.cancel) {
                // 点击取消
              } else {
                // 点击确定
                that.submitData(goodsList, type)
              }
            }
          })
          return
        }
        this.submitData(goodsList, type)
      }
    },
    gotoPage: throttle(
      0,
      false,
      function(url, type) {
        this._func(url, type)
      },
      false
    ),
    _func(url, type) {
      let idParams =
        type == "submit" || type == "save"
          ? { stockId: this.stockInfo.id }
          : { id: this.stockInfo.id }
      home
        .splitSave(
          {
            ...idParams,
            goodsList: JSON.stringify(this.addList),
          },
          this.getUrl(type).url
        )
        .then(data => {
          if (data.code !== 0) {
            wx.showToast({
              title: data.msg,
              icon: "none",
              duration: 2000,
            })
            return
          }
          this.resetData()
          wx.redirectTo({
            url: url,
          })
          wx.hideLoading()
        })
        .catch(err => {
          wx.showToast({
            title: err,
            icon: "none",
            duration: 2000,
          })
        })
    },
    async getProductListIdNotSplit() {
      // 这个是未拆分过得详情页数据获取
      const { data } = await home.getProductListIdNotSplit({ id: this.id })
      this.stockInfo = data.stockInfo
      this.stockInfo.beginPicUrlList = this.stockInfo.beginPicUrl.split(",")
      this.stockInfo.endPicUrlList = this.stockInfo.endPicUrl.split(",")
      this.l = 1
      this.lockL = this.l
    },
    async getProductListId() {
      // 这个是已经拆分过得详情页数据获取
      const { data } = await home.getProductListId({ id: this.id })
      this.addList = data.splitGoodsList
      this.addList.map(item => {
        item.isNew = 0, //1是 0否
        item.beginPicUrlList =
          item.beginPicUrl == null ? [] : item.beginPicUrl.split(",")
        item.endPicUrlList =
          item.endPicUrl == null ? [] : item.endPicUrl.split(",")
        item.beltTypeNameInput = dictMatching(
          wx.getStorageSync("beltType") || [],
          item.beltType
        )
        item.goodsLevelName = dictMatching(
          wx.getStorageSync("goodsLevel") || [],
          item.goodsLevel
        )
      })

      //l 从已有的商品开始
      let str = this.addList[this.addList.length - 1].goodsName
      let strIndex = str.lastIndexOf("-")
      str = str.substring(strIndex + 1, str.length)
      this.l = Number(str) + 1
      this.lockL = this.l

      this.stockInfo = data.orderInfo
      this.stockInfo.beginPicUrlList = this.stockInfo.beginPicUrl.split(",")
      this.stockInfo.endPicUrlList = this.stockInfo.endPicUrl.split(",")
    },
    add() {
      this.addList.push({
        isNew: 1, //1是 0否
        goodsName: `${this.stockInfo.goodsName}-${this.l++}`,
        l: this.l,
        remark: "",
        warehouseName: "",
        warehouseId: "",
        beltType: this.stockInfo.beltType,
        beltTypeNameInput: this.beltName,
        goodsLevel: this.stockInfo.goodsLevel,
        goodsLevelName: this.levelName,
        sizeHeight: "",
        sizeWidth: "",
        sizeLong: "",
        weight: "",
        beginPicUrl: "",
        endPicUrl: "",
        beginPicUrlList: [],
        endPicUrlList: [],
        open: true
      })
      //  向你自己定义的里面新增一条记录
    },
    routerToUrl(url) {
      wx.redirectTo({
        url,
      })
    },
    chooseImage(e, i) {
      var _this = this
      wx.chooseImage({
        sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ["album", "camera"], // 可以指定来源是相册还是相机，默认二者都有
        success: function(res) {
          // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
          _this.files = _this.files.concat(res.tempFilePaths)
          res.tempFilePaths.map((item, index) => {
            wx.uploadFile({
              url: `${Shop.BASE_URL}applet/buy/storage/common/upload`,
              filePath: item, // chooseImage上传的图片
              name: "file", // 需要传给后台的图片字段名称
              formData: item, // 需要传给后台的其他表单数据
              header: {
                Authorization: wx.getStorageSync("token"),
              },
              success: res => {
                if (res.statusCode == 200) {
                  let { code, url, msg } = JSON.parse(res.data)
                  if (code == 0) {
                    // _this.addList[i].beginPicUrl.push(`${Shop.BASE_URL}${url}`)
                    _this.addList[i].beginPicUrlList.push(`${url}`)
                    var myDate = new Date()
                    let time = formatDate(myDate, 'YYYY-MM-DD HH:ii:SS')
                    _this.addList[i].beginTime = time
                    _this.addList.push()
                  } else {
                    wx.showToast({
                      title: msg,
                      duration: 4000,
                      icon: "none",
                    })
                  }
                } else {
                  wx.showToast({
                    title: _this.local.uploadFail,
                    duration: 4000,
                    icon: "none",
                  })
                }
              },
            })
          })
        },
        fail: function() {},
        complete: function() {},
      })
    },
    chooseImageEnd(e, i) {
      var _this = this
      wx.chooseImage({
        sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ["album", "camera"], // 可以指定来源是相册还是相机，默认二者都有
        success: function(res) {
          // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
          _this.filesEnd = _this.filesEnd.concat(res.tempFilePaths)
          res.tempFilePaths.map((item, index) => {
            wx.uploadFile({
              url: `${Shop.BASE_URL}applet/buy/storage/common/upload`,
              filePath: item, // chooseImage上传的图片
              name: "file", // 需要传给后台的图片字段名称
              formData: item, // 需要传给后台的其他表单数据
              header: {
                Authorization: wx.getStorageSync("token"),
              },
              success: res => {
                if (res.statusCode == 200) {
                  let { code, url, msg } = JSON.parse(res.data)
                  if (code == 0) {
                    // _this.addList[i].endPicUrl.push(`${Shop.BASE_URL}${url}`)
                    _this.addList[i].endPicUrlList.push(`${url}`)
                    var myDate = new Date()
                    let time = formatDate(myDate, 'YYYY-MM-DD HH:ii:SS')
                    _this.addList[i].endTime = time
                    _this.addList.push()
                  } else {
                    wx.showToast({
                      title: msg,
                      duration: 4000,
                      icon: "none",
                    })
                  }
                } else {
                  wx.showToast({
                    title: _this.local.uploadFail,
                    duration: 4000,
                    icon: "none",
                  })
                }
              },
            })
          })
        },
        fail: function() {},
        complete: function() {},
      })
    },
    predivImageStart(e) {
      previewImage(e)
    },
    predivImageEnd(e) {
      previewImage(e)
    },
    predivImage1(e) {
      previewImage(e)
    },
    changeBeltTypeNameInput (e) {
      this.addList[e.currentTarget.dataset.i].beltTypeName = e.mp.detail.value
    },
    predivImageEnd1(e) {
      previewImage(e)
    },
  },
  data() {
    return {
      beltTypeNameInputFlag: false,
      beltTypeNameInput: '',
      l: 1,
      url: Shop.IMG_URL,
      goodsNameCenter: 0,
      sumWeight: 0,
      sumLong: 0,
      pages: 0,
      indexBeltPicker: 0,
      indexLevelPicker: 0,
      arrayLevel: ["A", "B", "C", "D", "E"],
      arrayBelt: ["1", "4", "2", "3", "6"],
      pdt: 66,
      local: wx.getStorageSync("local"),
      indexWarePicker: 0,
      arrayWarehouse: ["1号仓库", "2号仓库", "3号仓库", "4号仓库"],
      goodsInfo: {},
      splitGoodsList: [],
      stockInfo: {},
      addList: [],
      files: [],
      filesEnd: [],
      indexPicker: 1,
      array: ["美国", "中国", "巴西", "日本"],
      logs: [],
      fileList: [],
    }
  },
}
</script>

<style scoped lang="scss">
@import 'index';
.log-list {
  display: flex;
  flex-direction: column;
  padding: 40rpx;
}

.log-item {
  margin: 10rpx;
}
</style>
